package cn.schoolwow.util.module.query.resource.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;

import java.net.URL;

public class ParseStringAsJSONArrayFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        URL url = (URL) flowContext.checkData("url");
        String content = (String) flowContext.checkData("content");

        try {
            JSONArray jsonArray = JSONObject.parseArray(content);
            flowContext.putReturnData("jsonArray", jsonArray);
        }catch (JSONException e){
            throw new IllegalArgumentException("解析内容为JSONArray异常!文件路径:"+url);
        }
    }

    @Override
    public String name() {
        return "将字符串转化为JSONArray对象";
    }
}
